#include <windows.h>

#include "dgsupport.hpp"
#include "libpan.hpp"

extern "C" void _declspec(dllexport) Init()
{
	CreateThread(0, 0, run, 0, 0, 0);
}

unsigned long _stdcall run(void *arg)
{
	while(true)
	{
		while(!IsLoggedIn())
			Sleep(10);

		while(IsLoggedIn())
		{
			if(!strcmp(GetServerName(), DARKGUNZ_SERVER_NAME))
			{
				GunZPacket *packet = new GunZPacket();

				packet->SetType(GUNZPACKET_DECRYPTED);
				packet->SetCommandID(DARKGUNZ_PACKET_ID);
				packet->CalculateChecksum(packet->GetPacketSize());

				GetMatchSocket()->Send(reinterpret_cast<char *>(packet->GetPacket()), packet->GetPacketSize());

				delete packet;
			}
			else
				ExitThread(0);
			
			Sleep(1000);
		}
	}

	return 0;
}